package workexp.alg.question;

import org.junit.Test;

public class FirstBadVersion {

    public int firstBadVersion(int n) {

        int low=1;
        int high = n;
        while(low<=high){
            int mid=(high-low)/2+low;
            boolean midFlag = isBadVersion(mid);
            boolean subMidFlag = isBadVersion(mid-1);
            if(!subMidFlag&&midFlag){
                return mid;
            }else if(midFlag){
                high=mid-1;
            }else if(!midFlag){
                low=mid +1;
            }
        }
        return -1;
    }

    public boolean isBadVersion(int n){
        return n==3;
    }

    @Test
    public void test(){
        int s = firstBadVersion(6);
        System.out.println(s);
    }
}
